<template>
  <div class="main">
    <div class="salary">
      <el-input type="number" placeholder="请输入薪资" v-model="salary"></el-input>
    </div>
    <div class="form">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="用户id" prop="id"></el-table-column>
        <el-table-column label="昵称" prop="nickname"></el-table-column>
        <el-table-column label="性别" prop="sex"></el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <el-button size="mini" type="primary"
                       @click="examine(scope.row.id)">审批</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import cookie from "js-cookie";
import {examineApplication, queryApplication} from "@/http/api/restaurant";
import response from "@/http/response";

export default {
  name: "StafferExamine",
  data() {
    return {
      salary: 0,
      tableData: [],
    }
  },
  methods: {

    // 获取入职申请
    async getAll() {
      let result = await queryApplication({
        restaurantId: cookie.get('restaurantId')
      })
      if (result.code === response.success) {
        let data = result.data
        if (!data) {
          return this.tableData = []
        }
        // 性别转换
        for(let i = 0; i < data.length; i ++) {
          data[i].sex = (data[i].sex === '1') ? '男' : '女'
        }
        this.tableData = data
      }
    },

    // 审批入职申请
    async examine(userId) {
      let result = await examineApplication({
        restaurantId: cookie.get('restaurantId'),
        userId: userId,
        salary: this.salary,
      })
      if (result.code === response.success) {
        this.$message.success("请求成功")
        await this.getAll()
      }
    }
  },

  async mounted() {
    await this.getAll()
  }
}
</script>

<style lang="less" scoped>
.main {
  .salary {
    width: 300px;
  }
}
</style>